package io.itit.ecp.admin.provide.filter;

import com.alibaba.fastjson.serializer.ValueFilter;
import io.itit.grass.common.server.helper.DictHelper;
import io.itit.grass.common.utils.CommonUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * <p>
 *
 * @Author：Roy
 * @Description：预警键值转换
 * @Date：Create by 2023-12-04 15:28:53
 */
public interface IEarlyWarningFilter {

	String WARNING_TYPE = "warningType" ;
	String METER_CONDITION = "meterCondition" ;
	String PUSH_TYPE = "pushType" ;

	String EARLY_WARNING_WARNING_TYPE = "ecp-admin.earlyWarning.warningType" ;
	String EARLY_WARNING_METER_CONDITION = "ecp-admin.earlyWarning.meterCondition" ;
	String EARLY_WARNING_PUSH_TYPE = "ecp-admin.earlyWarning.pushType" ;

	class EarlyWarningExportFilter implements ValueFilter {

		private Map<String, String> warningTypeMap;
		private Map<String, String> meterConditionMap;
		private Map<String, String> pushTypeMap;

		public EarlyWarningExportFilter() {
			warningTypeMap = DictHelper.i().stringVlMap(EARLY_WARNING_WARNING_TYPE);
			meterConditionMap = DictHelper.i().stringVlMap(EARLY_WARNING_METER_CONDITION);
			pushTypeMap = DictHelper.i().stringVlMap(EARLY_WARNING_PUSH_TYPE);
		}

		@Override
		public Object process(Object object, String name, Object value) {
			if (StringUtils.equals(name, WARNING_TYPE)) {
				return CommonUtils.orElse(warningTypeMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, METER_CONDITION)) {
				return CommonUtils.orElse(meterConditionMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, PUSH_TYPE)) {
				return CommonUtils.orElse(pushTypeMap.get(CommonUtils.toString(value)), value);
			}
			return value;
		}

	}

	class EarlyWarningUploadFilter implements ValueFilter {

		private Map<String, String> warningTypeMap;
		private Map<String, String> meterConditionMap;
		private Map<String, String> pushTypeMap;

		public EarlyWarningUploadFilter() {
			warningTypeMap = DictHelper.i().stringLvMap(EARLY_WARNING_WARNING_TYPE);
			meterConditionMap = DictHelper.i().stringLvMap(EARLY_WARNING_METER_CONDITION);
			pushTypeMap = DictHelper.i().stringLvMap(EARLY_WARNING_PUSH_TYPE);
		}

		@Override
		public Object process(Object object, String name, Object value) {
			if (StringUtils.equals(name, WARNING_TYPE)) {
				return CommonUtils.orElse(warningTypeMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, METER_CONDITION)) {
				return CommonUtils.orElse(meterConditionMap.get(CommonUtils.toString(value)), value);
			}
			if (StringUtils.equals(name, PUSH_TYPE)) {
				return CommonUtils.orElse(pushTypeMap.get(CommonUtils.toString(value)), value);
			}
			return value;
		}

	}

}
